﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ServiceModel;

using WSU.Cheka.Data.Contracts;

namespace WSU.Cheka.Data.Services
{
    public class LessonMgrSvc : ILessonManager
    {
        #region "member fields"

        private IDictionary<string, Lesson> m_lessons;

        #endregion

        #region "constructor"

        // only the constructor without any parameter will be used
        // chekanote: this works fines because we are using "PerSesson" instance mode
        // so we can preserve some state between calls
        public LessonMgrSvc()
        {
            m_lessons = new Dictionary<string, Lesson>();
            Console.WriteLine("New service instance created.");
        }

        #endregion

        #region "implement contracts"

        public void Save(Lesson lesson)
        {
            m_lessons.Add(lesson.Name, lesson);
        }

        public Lesson Load(string name)
        {
            return m_lessons[name];
        }

        public Lesson[] GetAll()
        {
            return m_lessons.Values.ToArray();
        }

        #endregion
    }
}
